<!DOCTYPE html>
<html lang="zh">
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header :: header(~{::title},~{::link},~{})">
    <title>点餐</title>
    <link rel="icon" th:href="@{/assets/img/lcxm.ico}" type="image/ico">
</head>
<body class="body">
<!--导航-->
<div th:replace="common/nav :: nav(true)"></div>

<div class="container">

    <div class="row">
        <div style="margin-top: 20px;"></div>
        <div class="row">

            <form class="form-horizontal validate" role="form" method="post" th:action="@{/project/save}"
                  onsubmit="return checkForm(this);">

                <!-- 操作信息提示的地方 -->
                <div th:if="${remind}" class="alert alert-${ remind.level  }"
                     th:classappend="'alert-' + ${remind.level}">
                    <button data-dismiss="alert" class="close" type="button">
                        <i class="glyphicon glyphicon-remove"></i>
                    </button>
                    <span th:remove="tag" th:utext="${ remind.message }"></span>
                </div>

                <input type="hidden" id="projectId"  th:value="${projectUser?.project.id}" />
                <div class="col-sm-12 col-sm-offset-0">
                    <table class="table table-striped table-condensed table-bordered stable">
                        <caption>项目基本信息</caption>
                        <tbody>
                        <tr class="success">
                            <th>项目名称</th>
                            <th>状态</th>
                            <th>jira前缀</th>
                            <th>预计工时(分钟)</th>
                            <th>创建人(项目经理)</th>
                            <th>备注</th>

                        </tr>
                        <tr class="text-center text-danger lead">
                            <td th:text="${projectUser?.project.name}" >name</td>
                            <td th:text="${projectUser?.project.status}">status</td>
                            <td th:text="${projectUser?.project.jiraPrefix}">jiraPrefix</td>
                            <td th:text="${projectUser?.project.duration}">duration</td>
                            <td th:text="${projectUser?.project.createName}">usedTime</td>
                            <td th:text="${#strings.abbreviate(projectUser?.project.note,20)}" data-toggle="tooltip" th:title="${projectUser?.project.note}">note</td>
                        </tr>

                    </table>

                </div>
                <div class="col-sm-12 col-sm-offset-0">
                    <div class="action-bar">
                        <a class="btn btn-sm btn-success" id="addUser" title="新增人员">
                            <i class="glyphicon glyphicon-plus"></i> 新增人员
                        </a>
                    </div>

                    <table class="table table-striped  table-hover table-bordered stable">
                        <caption>项目人员列表(
                            <th:block th:text="${projectUser?.getUsers().size()}+'人'"/>
                            )
                        </caption>
                        <thead>
                        <tr class="text-center">
                            <th>工号</th>
                            <th>用户名</th>
                            <th>所属小组</th>
                            <th class="text-info">操作</th>
                        </tr>
                        </thead>
                        <tbody align="center">
                        <tr th:each="cur:${projectUser?.users}" >
                            <td th:text="${cur.userCode}" class="text-info">userCode</td>
                            <td th:text="${cur.userName}">userName</td>
                            <td th:text="${cur.groupName}">usedTime</td>
                            <td>
                                <div class="btn-group-dis">
                                    <button th:if="${cur.couldEdit}" class="btn btn-xs btn-danger action-post"
                                            type="button"
                                            th:attr="data-url='/project/deleteProjectUser/'+${cur.id}"
                                            data-toggle="tooltip"
                                            title="删除" data-confirm="确定删除吗?">
                                        <i class="glyphicon glyphicon-trash"></i>
                                        <i class="action-param" data-key="projectId" th:attr="data-value=${projectUser?.project.id}"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <!-- </c:forEach> -->
                        </tbody>
                    </table>
                </div>


                <div class="form-group clearfix">
                    <div class="col-sm-offset-4 col-sm-8">
                        <a type="button" class="btn btn-lg  btn-info" th:href="@{/project/}">
                            <i class="glyphicon glyphicon-repeat"></i> 返回
                        </a>
                    </div>
                </div>


            </form>

        </div>


    </div>
</div>

<!-- 引入通用js-->
<div th:replace="common/footer :: footer"></div>
<script>
    function checkForm(form) {

        return true;
    };

    $("#addUser").on("click", function(){
        $.confirm({
            title: '新增项目人员!',
            content: 'url:' + ctx+"user/list/" + $("#projectId").val(),
            columnClass:'col-md-12 ',
            buttons: {
                取消: function () {
                    $.alert('Canceled!');
                },
                somethingElse: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        let ids = this.$content.find('input[name="ids"]:checked').map(function() {
                            return $(this).val();
                        }).get();
                        if (!ids || ids.length == 0) {
                            $.alert('没有选择任何人员');
                            return;
                        }
                        let url = "project/addProjectUser/" + $("#projectId").val();
                       $request.post(url,{data:{ids:ids}},function(data){
                           if(data.success){
                               $.alert({
                                   title:'操作成功',
                                   content:'',
                                   onClose: function () {
                                       window.location.reload();
                                   }
                               });
                           }else{
                               $.alert(data.msg);
                           }
                       })
                    }
                }
            }
        });

    })

</script>

</body>
</html>